using UnityEngine;
using System.Collections;

public class SplashScript : MonoBehaviour {

	public GameObject WindowPrefab;
	
	// Use this for initialization
	IEnumerator Start () {
		if(!Application.isEditor)
		{
			if(PlayerPrefs.HasKey("StuffPreLoaded_0.01"))
			{
				StartCoroutine(StartTimer());
			}
			else
			{
				yield return StartCoroutine(LoadStuff());
				PlayerPrefs.SetString("StuffPreLoaded_0.01","StuffPreLoaded_0.01");
				PlayerPrefs.Save();
			}
		}
		else
			StartCoroutine(StartTimer());
	}
	
	IEnumerator LoadStuff()
	{
		GameObject g = Instantiate(WindowPrefab) as GameObject;
		g.transform.parent = this.transform.parent.parent;
		g.transform.localScale = Vector3.one;
		g.transform.localPosition = Vector3.back * 50;
		
		while(g != null)
		{
			yield return new WaitForSeconds(0.5f);
		}
		
		StartCoroutine(StartTimer());
		
		yield break;
	}
	
	IEnumerator StartTimer()
	{
		yield return new WaitForSeconds(1.5f);
		
		Application.LoadLevel("Base");
		
		yield break;
	}
}
